#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_LEN 1024

int main() {
    char *content_length_str = getenv("CONTENT_LENGTH");
    if (content_length_str == NULL) {
        printf("Content-Type: text/html\r\n\r\n");
        printf("<html><body><h1>Error: No data received</h1></body></html>");
        return 0;
    }

    int content_length = atoi(content_length_str);
    char buffer[MAX_LEN];
    if (fgets(buffer, content_length + 1, stdin) == NULL) {
        printf("Content-Type: text/html\r\n\r\n");
        printf("<html><body><h1>Error: Failed to read data</h1></body></html>");
        return 0;
    }

    char username[MAX_LEN];
    char password[MAX_LEN];
    sscanf(buffer, "username=%[^&]&password=%s", username, password);

    printf("Content-Type: text/html\r\n\r\n");
    printf("<html><body>");
    printf("<h1>Welcome!</h1>");
    printf("<p>Username: %s</p>", username);
    printf("<p>Password: %s</p>", password);
    printf("</body></html>");

    return 0;
}